package com.cjm.one.webmanager.controller.customer;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.custom.dto.UserChartItem;
import com.cjm.one.model.custom.entity.CustomerInfo;
import com.cjm.one.webmanager.service.customer.CustomerInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@Tag(name = "5-客户信息管理", description = "客户信息管理")
@RequestMapping("/manager/customer/info")
public class CustomerInfoController {
    @Resource
    private CustomerInfoService customerInfoService;
    @GetMapping("list")
    @Operation(summary = "查询客户信息列表")
    public Result<Page<CustomerInfo>> list(@RequestParam(defaultValue = "1") Integer current,
                                           @RequestParam(defaultValue = "5") Integer size,
                                           @RequestParam(required = false) String name,
                                           @RequestParam(required = false) String phone,
                                           @RequestParam(required = false) String email,
                                           @RequestParam(required = false) Long userId,
                                           @RequestParam(required = false) String level) {
        return Result.ok(customerInfoService.getList(current,size,name,phone,userId,level,email));
    }
    @GetMapping("/{id}")
    @Operation(summary = "查询客户信息")
    public Result<CustomerInfo> getInfo(@PathVariable Long id) {
        return Result.ok(customerInfoService.getById(id));
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "删除客户信息")
    public Result<Boolean> deleteInfo(@PathVariable Long id) {
        return Result.ok(customerInfoService.removeById(id));
    }

    @PutMapping
    @Operation(summary = "修改客户信息")
    public Result<Boolean> updateInfo(@RequestBody CustomerInfo customerInfo) {
        return Result.ok(customerInfoService.updateById(customerInfo));
    }

    @PostMapping
    @Operation(summary = "新增客户信息")
    public Result<Boolean> addInfo(@RequestBody CustomerInfo customerInfo) {
        return Result.ok(customerInfoService.addInfo(customerInfo));
    }

    @GetMapping("/summary")
    @Operation(summary = "客户统计信息")
    public Result<Map<String, Object>> getUserSummary(
            @RequestParam(defaultValue = "30d") String timeRange){
        return Result.ok(customerInfoService.getUserSummary(timeRange));

    }
    @GetMapping("/chart")
    @Operation(summary = "客户统计图表")
    public Result<List<UserChartItem>> getUserChart(
            @RequestParam(defaultValue = "30d") String timeRange){
        return Result.ok(customerInfoService.getUserChart(timeRange));
    }
    @PostMapping("/refund/{orderNo}")
    @Operation(summary = "退款虚假接口，测试用")
    public Result<Boolean> refund(@PathVariable("orderNo") String orderNo){
        return Result.ok(customerInfoService.refund(orderNo));
    }
}
